/***
 * @Author: Dina Helal
 */
package com.bfb;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

/***
 * 
 * Map overlay to add a pin on the map
 * 
 */
public class MapOverlay extends ItemizedOverlay {

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	public boolean tap = false;
	public ArrayList<Double> latitudes = new ArrayList<Double>();
	public ArrayList<Double> longitudes = new ArrayList<Double>();
	
	public MapOverlay(Drawable arg0) {
		super(boundCenterBottom(arg0));
		// TODO Auto-generated constructor stub
	}

	public void set(int i, OverlayItem item) {

		mOverlays.set(i, item);
	}

	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	@Override
	public boolean onTap(GeoPoint point, MapView mapView) {
		
		if (tap) {
			this.latitudes.add((double)point.getLatitudeE6() / 1E6);
			this.longitudes.add((double)point.getLongitudeE6() / 1E6);
			OverlayItem overlayitem = new OverlayItem(point, "", "");
			this.addOverlay(overlayitem);
			
		}
		return true;
	}
}
